package com.kaoqin.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.github.pagehelper.PageInfo;
import com.kaoqin.model.SysLog;
import com.kaoqin.service.SysLogService;
import com.kaoqin.util.DateUtil;
/**
* @ClassName: SysLogController 
* @Description: 日志查询
* @author Janus
* @date 2017年9月6日 下午5:19:08
 */
@Controller
@RequestMapping("log")
public class SysLogController {
	@Autowired
	private SysLogService sysLogService;
	
	@RequestMapping("list")
	public String list(HttpServletRequest request,SysLog log,Model model) {
		String statDate = request.getParameter("statDate");
		String endDate = request.getParameter("endDate");
		String opType = request.getParameter("opType");
		int pageN = log.getPageNum()==null ? 1:log.getPageNum();
		SysLog paraLog = new SysLog();
		if(StringUtils.isNotBlank(statDate)){
			statDate=statDate+" 00:00:00.0";
			paraLog.setParamStatDate(
					DateUtil.getFormatTimestamp(DateUtil.getDateTimeFormat(statDate), DateUtil.DATETIME_DEFAULT_FORMAT));
			statDate=statDate.replace(" 00:00:00.0", "");
		}
		if(StringUtils.isNotBlank(endDate)){
			endDate=endDate+" 23:59:59.0";
			paraLog.setParamEndDate(
					DateUtil.getFormatTimestamp(DateUtil.getDateTimeFormat(endDate), DateUtil.DATETIME_DEFAULT_FORMAT));
			endDate=endDate.replace(" 23:59:59.0", "");
		}
		paraLog.setOpEditData(opType);
		paraLog.setPageNum(pageN);
		paraLog.setOrderSql(" order by ts.op_date desc");
		PageInfo<SysLog> page = new PageInfo<>();
		page = sysLogService.findAll(paraLog);
		List<SysLog> list = page.getList();
		model.addAttribute("SysLogList",list==null?new ArrayList<>():list);
		model.addAttribute("Page", page);
		model.addAttribute("statDate", statDate);
		model.addAttribute("endDate", endDate);
		model.addAttribute("opType", opType);
		return "sysLog/list";
	}
}
